<template>
  <div>
    <el-table :data="tableData" style="width: 100%">
      <el-table-column label="ID" align="center" prop="sid" />
      <el-table-column label="药品图片" align="center" prop="surl" >
        <template #default="scope">
          <el-image :src="scope.row.surl" style="width: 100px; height: 100px"></el-image>
        </template>
      </el-table-column>
      <el-table-column label="商品名称" align="center" prop="sname" />
      <el-table-column label="商品简介" align="center" prop="brief" />
      <el-table-column label="注意事项" align="center" prop="detail" />
      <el-table-column label="宣传图片" align="center" prop="jurl" >
        <template #default="scope">
          <el-image :src="scope.row.jurl" style="width: 100px; height: 100px"></el-image>
        </template>
      </el-table-column>
      <el-table-column label="商品价格" align="center" prop="detail" />
      <el-table-column label="药品外键" align="center" prop="cid" />
      <el-table-column label="月租价" align="center" prop="yuezu" />
      <el-table-column label="销售价" align="center" prop="xiaoshou" />
      <el-table-column label="用户ID" align="center" prop="uid" />
      <el-table-column
          prop="status"
          label="状态">
        <template slot-scope="scope">
          <div v-if="scope.row.status == 1">
            <van-icon name="success" color="red" />
            <span>通过</span>
          </div>
          <div v-if="scope.row.status == 2">
            <van-icon name="success" color="green" />
            <span>不通过</span>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="dianji(scope.row)"
          >通过
          </el-button>
          <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="dianji2(scope.row)"
          >不通过
          </el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>


<script>
import axios from "axios";

export default {
  data() {
    return {
      tableData: [],
      dialogVisible:false,
      form:{
        sname:'',
        brief:'',
        detail:'',
        jurl:'',
        surl:'',
        yuezu:'',
        xiaoshou:'',
        uid:'',
        cid:'',
        price:'',
        sid:'',
      }
    }
  }, methods: {
    dianji(row) {
      console.log('----------'+row.sid);
      axios.get("http://localhost:9000/plant-Addproduct/addproduct/updatestatus?sid="+row.sid).then(res => {
        if (res.data ==1) {
          this.$message.success('审核通过')
          this.getList()
        } else {
          this.$message.error(res.msg)
        }
      });
    },
    dianji2(row) {
      console.log('----------'+row.sid);
      axios.get("http://localhost:9000/plant-Addproduct/addproduct/updatestatus1?sid="+row.sid).then(res => {
        if (res.data ==1) {
          this.$message.success('审核不通过')
          this.getList()
        } else {
          this.$message.error(res.msg)
        }
      });
    },
    getList() {
      axios.get("http://localhost:9000/plant-Addproduct/addproduct/findAddproduct").then(res => {
        this.tableData = res.data;
      })
    }
  },
  created() {
    this.getList();
  }
}
</script>